package com.xinghou.platform.server.api.controller;

import com.xinghou.platform.entity.req.ShareInfoReq;
import com.xinghou.platform.server.api.bussiness.SearchInfoBusinessService;
import com.xinghou.platform.server.api.bussiness.UserInfoBusinessService;
import com.xinghou.platform.util.StringUtils;
import com.xinghou.platform.util.exception.DBExceptionEnums;
import com.xinghou.platform.util.exception.ServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 分享信息处理
 * @author xuzhen
 *
 */
@Controller
public class GetSearchInfoController extends BaseControl {



	@Resource
	private SearchInfoBusinessService searchInfoBusinessService;

	@Resource
	private UserInfoBusinessService userInfoBusinessService;
	
	/**
	 * 综合搜索查询
	 * @param shareInfoReq
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/findRangeList", method = {RequestMethod.POST})
	public String findRangeStoreList(@RequestBody ShareInfoReq shareInfoReq,
			HttpServletRequest request, HttpServletResponse response){
		Long start=System.currentTimeMillis();
		String key=shareInfoReq.getKey();
			if(StringUtils.isBlank(shareInfoReq.getUserid())){
				throw new ServiceException(DBExceptionEnums.USER_IS_NULL);
			}else if(StringUtils.isBlank(shareInfoReq.getType())){
				throw new ServiceException(DBExceptionEnums.TYPE_IS_NULL);
			}
		if(StringUtils.isEmpty(shareInfoReq.getPageno()))
			shareInfoReq.setPageno("1");
		if(StringUtils.isEmpty(shareInfoReq.getPagesize()))
			shareInfoReq.setPagesize("30");
		if(StringUtils.isEmpty(shareInfoReq.getDistance()))
			shareInfoReq.setDistance("5");
		userInfoBusinessService.checkclosureByUserId(shareInfoReq.getUserid());
		     int type=Integer.valueOf(shareInfoReq.getType());
				//1:门店 2：星友
				switch (type) {
				case 1:
					return response(searchInfoBusinessService.getShopInfos(shareInfoReq));
				case 2:
					return response(searchInfoBusinessService.getFriendInfos(shareInfoReq, 0));
				default:
					return null;
				}
	}


	
}
